﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
using System.Web.UI.WebControls;
using weikebuluo.Model;
using weikebuluo.DAL;

using weikebuluo.Common;

namespace weikebuluo.web.admin.main
{
    public partial class password : weikeweixin.web.admin.cs.adminbase
    {
        a_user_dal userdal = new a_user_dal();
        a_user_model usermodel = new a_user_model();

        protected void Page_Load(object sender, EventArgs e)
        {
            switch (Request.Form["action"])
            {
                case "password":
                    updatepassword();
                    break;
            }
        }




        private void updatepassword()
        {

            DataTable dtuser = userdal.GetList("user_name='" + user_name + "' and user_psw='" + MD5Provider.GetMd5(Request.Form["oldpassword"]) + "'").Tables[0];
            if (dtuser.Rows.Count > 0)
            {
                Session["user_name"] = dtuser.Rows[0]["user_name"];
                usermodel = userdal.GetModel(int.Parse(user_id));


                string password_a=Request.Form["newpassword1"];
                string password_b=Request.Form["newpassword2"];

                //usermodel.user_psw = MD5Provider.GetMd5(Request.Form["newpassword2"]);
                //usermodel.user_psw = MD5Provider.GetMd5(password_b);
                //userdal.Update(usermodel);
                //Response.Write("<script Language=\"Javascript\">alert(\"修改成功！\");");
                //Response.Write("</script>");
                //Response.Write("<script Language=\"Javascript\">location=\"password.aspx\";");
                //Response.Write("</script>");

                if (password_a == password_b)
                {
                    usermodel.user_psw = MD5Provider.GetMd5(password_b);
                    userdal.Update(usermodel);

                  
                    Response.Write("<script Language=\"Javascript\">alert(\"修改成功！\");");
                    Response.Write("</script>");
                    Response.Write("<script Language=\"Javascript\">location=\"password.aspx\";");
                    Response.Write("</script>");
                }
                else
                {
                    Response.Write("<script Language=\"Javascript\">alert(\"亲，两次输入的新密码不同哦！\");");
                    Response.Write("</script>");
                    Response.Write("<script Language=\"Javascript\">location=\"password.aspx\";");
                    Response.Write("</script>");
                }

            }
            else
            {
                Response.Write("<script Language=\"Javascript\">alert(\"初始密码不正确，请重新输入\");");
                Response.Write("</script>");
                Response.Write("<script Language=\"Javascript\">location=\"password.aspx\";");
                Response.Write("</script>");
            }
        }

    }
}